﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Classes;

namespace OfficeManager_v0._1
{
    public partial class AddOrEditTelephonePost : Form
    {
        Office mOffice;
        bool edit;
        TelephonePost oldPost;

        public AddOrEditTelephonePost(Office aOffice, bool edit, TelephonePost oldPost = null)
        {
            mOffice = aOffice;
            this.edit = edit;

            InitializeComponent();
            if (edit)
            {
                this.oldPost = oldPost;
                textBoxNumber.Text = oldPost.TelephoneNumber.Number;
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!edit)
                {
                    TelephonePost post = new TelephonePost(textBoxNumber.Text);
                    mOffice.TelephonePost.Add(post);
                }
                else
                {
                    oldPost.TelephoneNumber.Number = textBoxNumber.Text;
                }    
            }
            catch (Exception exc)
            {
                MessageBox.Show("Въведените данни са некоректни!");
            }

            this.Close();
            this.Dispose();
        }
    }
}
